1. Field of the Invention
This invention relates to computer systems and, more particularly, to apparatus and a method for improving the performance of a microprocessor in executing programs translated from programs designed for execution by a different processor.
2. History of the Prior Art
Recently, a new microprocessor was developed which combines a simple but fast host processor (called a xe2x80x9cmorph hostxe2x80x9d) and software (referred to as xe2x80x9ccode morphing softwarexe2x80x9d) to execute application programs designed for a target processor having an instruction set different than that of the morph host processor. The morph host processor executes the code morphing software which translates the target application programs dynamically into host processor instructions able to accomplish the purpose of the target application programs. As the instructions are translated, they are stored in a translation buffer where they may be accessed without further translation. Although the initial translation of a program is slow, once translated, many of the steps normally required for hardware to execute a program are eliminated. The new microprocessor has demonstrated that a simple fast processor designed to expend little power is able to execute translated xe2x80x9ctargetxe2x80x9d instructions at a rate equivalent to that of the xe2x80x9ctargetxe2x80x9d processor for which the programs were designed.
Complicating the problem of translation are the various interruptions and exceptions which are carried out by the hardware of a target computer and its operating system in order for the computer system to operate. When a target exception is taken during the operation of a target computer, state of the computer at the time of the exception must be saved typically by calling a microcode sequence to accomplish the operation, the correct exception handler must be retrieved, the exception must be handled, then the correct point in the program must be found for continuing with the program. Often this requires that the program revert to the state of the target computer at the point the exception was taken. The results provided by the hardware and software of the target computer to accomplish these operations must somehow be provided by the process of translation so that the morph host processor is able to correctly respond to these exceptions.
In order to be able to run programs designed for other processors at a rapid rate, the morph host processor includes a number of hardware enhancements. One of these enhancements is a gated store buffer which stores temporarily memory stores resulting from the execution of the translated sequence of instructions in the translation buffer. A second enhancement is a set of host registers (in addition to normal working registers) which store state of the target processor at the beginning of any sequence of target instructions being translated. Sequences of target instructions are translated into host instructions and executed. The sequences begin and end at points at which target state is known. If the translated instructions execute without raising an exception, the memory stores generated by the execution of the translated host instructions are stored in memory (committed to memory) by a commit instruction; and the registers holding the target state are updated to the target state at the point at which the sequence completed.
However, if an exception occurs during the execution of the sequence of host instructions, processing stops; and the entire operation may be returned to the beginning of the sequence of target instructions at which known state of the target processor exists. This allows rapid and accurate handling of exceptions incurred while dynamically translating and executing instructions.
It will be noted that the method by which the new microprocessor handles the execution of translations by placing the effects generated by execution in temporary storage until execution of the translation has been completed is effectively a rapid method of speculating. The new microprocessor, in fact, uses the same circuitry for speculating on the outcome of other operations. For example, by temporarily holding the results of execution of instructions reordered by a software scheduler from naively translated instructions, more aggressive reordering may be accomplished than has been attempted by the prior art. When such a reordered sequence of instructions executes to produce a correct result, the memory stores resulting from execution of the reordered sequence may be committed to memory and target state may be updated. If the reordered sequence generates an exception while executing, then the state of the processor may be rolled back to target state at the beginning of the sequence and a more conservative approach taken in executing the sequence.
One of the most advantageous features of the new microprocessor is its ability to link together long sequences of translated instructions. Once short sequences of target instructions have been translated and found to execute without exception, it is possible to link large numbers of these short sequences together to form long sequences of instructions. This allows a translated program to be executed at great speed because the microprocessor need not go through all of the steps (such as looking up each of the shorter translated sequences) normally taken by hardware processors to execute instructions. Even more speed may be attained than might be expected because, once long sequences are linked, it is often possible for an optimizer to eliminate many of the steps from the long sequences without changing the results produced. Hardware optimizers have never been able to optimize sequences of instructions long enough to allow the patterns which allow significant optimization to become apparent.
Whenever a processor is executing instructions, it is running in some particular mode which has various characteristics. The instructions of an application must be executed in the correct mode to consistently produce the correct results. These characteristics of a mode are effectively background for the instructions and may be considered to be a part of the instructions. As a processor executes instructions, certain of those instructions may change the characteristics and thus the mode of operation. This requires that a number of characteristics of the microprocessor be set differently to handle these different modes. The characteristics of machine state which must be set correctly in order for instructions to provide the correct result are typically referred to as the context in which the instructions execute. Context may be said to summarize the current state of the machine that is necessary to produce the correct result from the execution of instructions.
A major problem which the new microprocessor faces in translating sequences of instructions designed for a target processor having a first instruction set into a sequence of host instructions of a different instruction set is caused by the need to maintain context while translating and running.
There are a myriad of different things which can constitute context in executing a program. The recitation of just a few of the many elements which can constitute context illustrates just how complicated the problem is. Those skilled in the art will understand that there are literally hundreds of possible items of context.
Many microprocessors are designed to function with application programs having instructions of eight bit, sixteen bit, and thirty-two bit words lengths depending on the capability of the operating system in use. Often the same instructions are utilized with applications written with instructions of different word lengths. However, if the microprocessor attempts to execute sixteen bit instructions while its characteristics are set for executing thirty-two bit instructions, the instructions will probably not execute correctly. Thus, instruction word length can be considered as target processor context for execution purposes.
As another example, instructions execute at different levels of permission. Thus, some instructions can only be executed by one having the highest level of access; other instructions may be executed by users at a lower level as well as all those at a higher level. It is necessary to maintain the same access levels when executing translated instructions so that applications cannot interfere with assets of unrelated applications.
Intel X86 based microprocessors allow applications to designate where the various portions (segments) of code and data are stored in memory. For example, a program may designate base addresses and lengths for segments of the program so that a code segment starts at one base address and continues through some amount of memory while a data segment starts at a different base address and includes a different amount of memory. Alternatively, a program may designate a single flat segment to be used for storing all instructions, data, and other elements of the program. Further, all segments for one program may start at the same base address yet run to different ending addresses. Consequently, the arrangement of base addresses being utilized is a very important characteristic in executing instructions. A confusion in the areas of memory allotted for different uses will probably keep a program from executing instructions with the proper results. Thus, this may be an important element of context.
If an application is designed to execute with paging enabled, then the application must allow for paging exceptions which may occur. If an application is designed with paging off, then no paging exceptions can occur. Paging may thus be an important element of context.
There are many other characteristics that must be the same whenever the instructions are executed as when the instructions were compiled for the instructions to produce the correct results. With complicated instruction sets such as those used by Intel X86 processors, the number of characteristics which constitute context is quite large.
As with execution of instructions by the target processor, it is necessary that host instructions translated from target instructions maintain the context of the original processor for which the target instructions were designed when those translated instructions are executed in order for the same results to be produced by the host system. Since those items of context which may effect different results from the instructions need to remain constant from translation to execution, this would seem to require that literally hundreds of elements of context would need to be made a part of each translation in order to assure that the results produced be correct.
While it is critical when executing instructions on a processor to produce correct results, it is also desirable to execute instructions as rapidly as possible. This is generally accomplished by producing code which runs as efficiently as possible. The context or machine state controls just how efficient the code may be made. There are many characteristics of the machine state in which instructions execute which affect the efficiency of translation and execution and may make the instructions run faster or have some other desirable effect on the execution. In all cases, it is important that instructions which are executed in a particular mode on the target microprocessor be executed in an environment having characteristics set to execute instructions in the same mode in the host system. Furthermore, it is important that the translation context in which optimizing translation of the target code is carried out be maintained when that optimized code is executed.
Consequently, it is desirable to provide apparatus and methods by which a microprocessor which executes instructions translated from instructions designed for a target processor having a different instruction set can maintain context of the target processor so that execution of the translated instructions provides correct results.
It is equally desirable that the speed secured through the dynamic translation and optimizing practiced by the new microprocessor be maintained in the process of assuring that the translation is executed in the same context as that for which it was originally designed.
It is therefore an object of the present invention to assure that the translated instructions are executed in the same translation context as that in which they were originally translated and to do this, whenever possible, without slowing execution of the translated instructions.
This and other objects of the present invention are accomplished by a method which maintains the translation context for each portion of translated instructions, compares the translation context in which the morph host is functioning whenever a new portion of translated instructions is to be executed with the translation context at translation of the portion of translated instructions, allows execution if the translation contexts are the same, and forces a search for a different translation or a retranslation of the original instructions from which the portion of translated instructions was derived if the translation contexts differ.
These and other objects and features of the invention will be better understood by reference to the detailed description which follows taken together with the drawings in which like elements are referred to by like designations throughout the several views.